//
//  RecordViewController.m
//  Manager
//
//  Created by 彭凯敏 on 15/8/18.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "RecordViewController.h"
#import "AlreadySignViewController.h"
#import "UnsignedViewController.h"
#import "DontLookViewController.h"
#import "RecordCell.h"
#import "ViewRoomLogic.h"
#import "TestViewController.h"
#import "LoginViewController.h"



@interface RecordViewController ()
{
    
    NSMutableArray *titleArray;
    NSArray *imageArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation RecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self homeBaseCtlSetTitle:@"接单记录" andWithBackType:BackZero];

    
    [self baseCtlSetLeftBtnTitle:nil andWithRightTitle:@"查看房源"];
    
    [self.rightNavgationItem setAction:@selector(clickRoomRecord:)];
    [_tableView setLineType:TableViewLineTypeAll];
    
    titleArray = [@[@"已签约",@"未签约",@"不看房",@"测试"]mutableCopy];
    
    imageArray = @[@"record0",@"record1",@"record2",@"record0"];
}

-(void)viewWillAppear:(BOOL)animated {
    NSArray *array = [[ViewRoomLogic shareInstance] getOrderModelArray_6_7];
    if (array != nil && array.count > 0) {
        titleArray[0] = [NSString stringWithFormat:@"已签约 (%lu)",(unsigned long)array.count];
    } else {
        titleArray[0] = @"已签约";
    }
    array = [[ViewRoomLogic shareInstance] getOrdeModelArrayByStatus:@(ViewOrderStatusOrderNotSign).stringValue];
    if (array != nil && array.count > 0) {
        titleArray[1] = [NSString stringWithFormat:@"未签约 (%lu)",(unsigned long)array.count];
    } else {
        titleArray[1] = @"未签约";
    }
    array = [[ViewRoomLogic shareInstance] getOrdeModelArrayByStatus:@(ViewOrderStatusOrderNotView).stringValue];
    if (array != nil && array.count > 0) {
        titleArray[2] = [NSString stringWithFormat:@"不看房 (%lu)",(unsigned long)array.count];
    } else {
        titleArray[2] = @"不看房";
    }
    [_tableView reloadData];
}



#pragma mark - UITableViewDelegate & UITableViewDataSource
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        AlreadySignViewController *vc = [[AlreadySignViewController alloc]init];
        HideTabbar(vc);
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.section == 1)
    {
         UnsignedViewController *vc = [[UnsignedViewController alloc]init];
        HideTabbar(vc);
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.section == 2)
    {
        DontLookViewController *vc = [[DontLookViewController alloc]init];
        HideTabbar(vc);
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.section == 3)
    {
        TestViewController *vc = [[TestViewController alloc]init];
        HideTabbar(vc);
        [self.navigationController pushViewController:vc animated:YES];
        
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 13;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return titleArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"RecordCell";
    RecordCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell)
    {
        [tableView registerNib:[UINib nibWithNibName:@"RecordCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
    }
    cell.cellImage.image = ImageName(imageArray[indexPath.section]);
    
    cell.titleLabel.text = titleArray[indexPath.section];
    
    
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
    
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
#ifdef __IPHONE_8_0
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
#endif
    
    
}

- (void)clickRoomRecord:(UIBarButtonItem *)item
{
    WebViewController *web = [[WebViewController alloc]init];
    web.urlStr = @"http://180.150.186.187/show/public/Room/list?src=preview";
    HideTabbar(web);
    [self.navigationController pushViewController:web animated:YES];
}

@end
